//
//	Created By Pavel Yankelevich
//	Monday, March 24, 2008
//
using System;
using fit;
using OneDayModel.Interfaces;
using OneDayModel.Model;
using OneDayModel.Tests.Fits.UIUsers;

namespace OneDayModel.Tests.Fits.Fixtures.Scenarios
{
    public class CreateAlbumFixture : Fixture
    {
        private string albumName;
        private CreateAlbumUser createAlbumUser;

        public void CreateAlbum()
        {
            UsersFactory userFactory =
                (UsersFactory)TestUtils.ContextManager.TestContext[typeof(UsersFactory).ToString()];

            createAlbumUser = userFactory.GetCreateAlbumUser();
        }

        public void Create()
        {
            createAlbumUser.SetAlbumName(albumName);
            createAlbumUser.CreateAlbum();
        }

        public void AlbumName(string albumName)
        {
            this.albumName = albumName;
        }

        public void OwnerAlias(string alias)
        {
            if (SessionContext.GetInstance().User == null)
            {
                IRepository repository = ApplicationContext.GetInstance().Repository;
                IUser owner = repository.GetUserByAlias(alias);

                SessionContext.GetInstance().User = owner;

                ((IOnlineCache)repository).RegisterUserOnline(alias);
            }
        }

        public string ShownAlbum()
        {
            try
            {
                return string.Format("'{0}'", createAlbumUser.GetShowAlbumName());
            }
            catch (NullReferenceException)
            {
                return "No album shown";
            }
        }

        public string ShownError()
        {
            return createAlbumUser.GetShownError();
        }
    }
}